package com.yykj.weifenxiao.server.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yykj.drup.client.Category;
import com.yykj.weifenxiao.server.mapper.CategoryDao;
import com.yykj.weifenxiao.server.service.CategoryService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zengg
 * @since 2022-03-10
 */
@Service
@AllArgsConstructor
public class CategoryServiceImp extends ServiceImpl<CategoryDao, Category> implements CategoryService {


    @Override
    public Integer initCategory(String categoryId) {
        Category category = this.findByCategoryId(categoryId);
        if (category == null){
            category = new Category();
            category.setCategoryId(categoryId);
            this.save(category);
        }
        return category.getId();
    }

    @Override
    public Category findByCategoryId(String categoryId) {
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        wrapper
                .eq(Category::getCategoryId,categoryId)
                .eq(Category::getIsDeleted,0);
        return this.getOne(wrapper);
    }
}
